﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_modifyGoal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["userid"] != null && !Request.QueryString["userid"].ToString().Equals(""))
        {
            string userid = Request.QueryString["userid"].ToString();
            lb_user_id.Text = userid;
            DataTable dt = DB.getGoals(userid);
            gv_goal.DataSource = dt;
            gv_goal.DataBind();
            Session["dtGoal"] = dt;
            
        }
    }
    protected void btn_saveGoal_Click(object sender, EventArgs e)
    {
        string userid = lb_user_id.Text;
        if (tb_goal.Text.Equals("")) {
            lb_msg.Text="Your must asign a value.";
            lb_msg.Visible=true;
            return;
        }
        int goal = int.Parse(tb_goal.Text);
        DB.InsertGoal(goal, lb_user_id.Text);
        lb_msg.Text = "Succesfull";
        lb_msg.Visible = true;
        DataTable dt = DB.getGoals(userid);
        gv_goal.DataSource = dt;
        gv_goal.DataBind();
        Session["dtGoal"] = dt;
    }

    protected void btn_close_Click(object sender, EventArgs e)
    {
        String csname1 = "ClosePopupScript";
        Type cstype = this.GetType();
        ClientScriptManager cs2 = Page.ClientScript;
        string script = "window.close();";
        if (!cs2.IsStartupScriptRegistered(cstype, csname1))
        {
            cs2.RegisterStartupScript(cstype, csname1, script, true);
        }
    }
    protected void gv_goal_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataTable dt = null;
        if (Session["dtGoal"] != null) dt = (DataTable)Session["dtGoal"];
        gv_goal.PageIndex = e.NewPageIndex;
        gv_goal.DataSource = dt;
        gv_goal.DataBind();
    }
}